const Http = require('../../models/douban.js');
Page({

   /**
    * 页面的初始数据
    */
   data: {
      movies:{

      }
   },

   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: async function (options) {
      var storageData = wx.getStorageSync('movies');
      if(storageData){
         this.setData({
            movies:storageData
         });
      }else{
         var movies = {};
         var top250 = await Http.getTop250();
         var inTheaters = await Http.getTheaters();
         var comingSoon = await Http.getComing();
   
         movies.inTheaters = {};
         movies.inTheaters.title = "正在热映";
         movies.inTheaters.data = inTheaters.subjects.slice(0,3);
         movies.inTheaters.subTitle = "in_theaters";
   
         movies.comingSoon = {};
         movies.comingSoon.title = "即将上映";
         movies.comingSoon.data = comingSoon.subjects.slice(0,3);
         movies.comingSoon.subTitle = "coming_soon";
   
         movies.top250 = {};
         movies.top250.title = "豆瓣top250";
         movies.top250.data = top250.subjects.slice(0,3);
         movies.top250.subTitle = "top250";
         
         wx.setStorageSync('movies', movies)
         this.setData({
            movies
         })
      }
   },
   more(event){
      let {title,nav} = event.currentTarget.dataset;
      console.log(nav)
      wx.navigateTo({
         url: '/pages/movie-more/movie-more?title='+title+'&nav='+nav,
      });
   }
})